home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / src / bin / crayola / common / crayList.c < prev    next >
C/C++ Source or Header  |  1993-10-27  |  8KB  |  212 lines

  1. #include "geom.h"
  2. #include "listP.h"
  3. #include "crayolaP.h"
  4.  
  5. void *cray_list_HasColor(int sel, Geom *geom, va_list args);
  6. void *cray_list_HasVColor(int sel, Geom *geom, va_list args);
  7. void *cray_list_HasFColor(int sel, Geom *geom, va_list args);
  8.  
  9. void *cray_list_CanUseVColor(int sel, Geom *geom, va_list args);
  10. void *cray_list_CanUseFColor(int sel, Geom *geom, va_list args);
  11.  
  12. void *cray_list_UseVColor(int sel, Geom *geom, va_list args);
  13. void *cray_list_UseFColor(int sel, Geom *geom, va_list args);
  14.  
  15. void *cray_list_EliminateColor(int sel, Geom *geom, va_list args);
  16.  
  17. void *cray_list_SetColorAll(int sel, Geom *geom, va_list args);
  18. void *cray_list_SetColorAt(int sel, Geom *geom, va_list args);
  19. void *cray_list_SetColorAtV(int sel, Geom *geom, va_list args);
  20. void *cray_list_SetColorAtF(int sel, Geom *geom, va_list args);
  21.  
  22. void *cray_list_GetColorAt(int sel, Geom *geom, va_list args);
  23. void *cray_list_GetColorAtV(int sel, Geom *geom, va_list args);
  24. void *cray_list_GetColorAtF(int sel, Geom *geom, va_list args);
  25.  
  26. #define MAX_METHODS 14
  27. static craySpecFunc methods[] = {
  28.   "crayHasColor", cray_list_HasColor,
  29.   "crayHasVColor", cray_list_HasVColor,
  30.   "crayHasFColor", cray_list_HasFColor,
  31.   
  32.   "crayCanUseVColor", cray_list_CanUseVColor,
  33.   "crayCanUseFColor", cray_list_CanUseFColor,
  34.   
  35.   "crayUseVColor", cray_list_UseVColor,
  36.   "crayUseFColor", cray_list_UseFColor,
  37.   
  38.   "crayEliminateColor", cray_list_EliminateColor,
  39.   
  40.   "craySetColorAll", cray_list_SetColorAll,
  41.   "craySetColorAt", cray_list_SetColorAt,
  42.   "craySetColorAtV", cray_list_SetColorAtV,
  43.   "craySetColorAtF", cray_list_SetColorAtF,
  44.   
  45.   "crayGetColorAt", cray_list_GetColorAt,
  46.   "crayGetColorAtV", cray_list_GetColorAtV,
  47.   "crayGetColorAtF", cray_list_GetColorAtF
  48.   };
  49.  
  50.  
  51. cray_list_init() {
  52.   crayInitSpec(methods, MAX_METHODS, GeomClassLookup("list"));
  53.   return 0;
  54. }
  55.  
  56. static Geom *ListElement(Geom *list, int elem) {
  57.   int i;
  58.   List *l = (List *)list;
  59.   
  60.   for (i = 0; i < elem && l != NULL; i++) l = l->cdr;
  61.  
  62.   if (l == NULL) {
  63.     OOGLError(1, "Unable to retrieve list element %d\n", elem);
  64.     return NULL;
  65.   }
  66.  
  67.   return l->car;
  68. }
  69.  
  70. /* 
  71.  * Performs the named function (with its arguements included) on each 
  72.  * element of the list found in the variable geom, then returns the
  73.  * result of all of them |'d together
  74.  */
  75. #define LIST_EACH(list, func) \
  76. { \
  77.   int val; \
  78.   for (val = 0; list = (Geom*)((List *)(list))->cdr;) \
  79.     val |= (int)func; \
  80.   return (void *)val; \
  81. }
  82.  
  83. void *cray_list_HasColor(int sel, Geom *geom, va_list args) {
  84.   int *gpath = va_arg(args, int *);
  85.   if (gpath != NULL) 
  86.     return (void *)(crayHasColor(ListElement(geom, *gpath), gpath + 1));
  87.   LIST_EACH(geom, crayHasColor(((List *)geom)->car, NULL));
  88. }
  89.  
  90. void *cray_list_HasVColor(int sel, Geom *geom, va_list args) {
  91.   int *gpath = va_arg(args, int *);
  92.   if (gpath != NULL) 
  93.     return (void *)(crayHasVColor(ListElement(geom, *gpath), gpath + 1));
  94.   LIST_EACH(geom, crayHasVColor(((List *)geom)->car, NULL));
  95. }
  96.  
  97. void *cray_list_HasFColor(int sel, Geom *geom, va_list args) {
  98.   int *gpath = va_arg(args, int *);
  99.   if (gpath != NULL) 
  100.     return (void *)(crayHasFColor(ListElement(geom, *gpath), gpath + 1));
  101.   LIST_EACH(geom, crayHasFColor(((List *)geom)->car, NULL));
  102. }
  103.  
  104. void *cray_list_CanUseVColor(int sel, Geom *geom, va_list args) {
  105.   int *gpath = va_arg(args, int *);
  106.   if (gpath != NULL) 
  107.     return (void *)(crayCanUseVColor(ListElement(geom, *gpath), gpath + 1));
  108.   LIST_EACH(geom, crayCanUseVColor(((List *)geom)->car, NULL));
  109. }
  110.  
  111. void *cray_list_CanUseFColor(int sel, Geom *geom, va_list args) {
  112.   int *gpath = va_arg(args, int *);
  113.   if (gpath != NULL) 
  114.     return (void *)(crayCanUseFColor(ListElement(geom, *gpath), gpath + 1));
  115.   LIST_EACH(geom, crayCanUseFColor(((List *)geom)->car, NULL));
  116. }
  117.  
  118. void *cray_list_UseVColor(int sel, Geom *geom, va_list args) {
  119.   ColorA *c = va_arg(args, ColorA *);
  120.   int *gpath = va_arg(args, int *);
  121.   if (gpath != NULL) 
  122.     return (void *)(crayUseVColor(ListElement(geom, *gpath), c, gpath + 1));
  123.   LIST_EACH(geom, crayUseVColor(((List *)geom)->car, c, NULL));
  124. }
  125.  
  126. void *cray_list_UseFColor(int sel, Geom *geom, va_list args) {
  127.   ColorA *c = va_arg(args, ColorA *);
  128.   int *gpath = va_arg(args, int *);
  129.   if (gpath != NULL) 
  130.     return (void *)(crayUseFColor(ListElement(geom, *gpath), c, gpath + 1));
  131.   LIST_EACH(geom, crayUseFColor(((List *)geom)->car, c, NULL));
  132. }
  133.  
  134. void *cray_list_EliminateColor(int sel, Geom *geom, va_list args) {
  135.   int *gpath = va_arg(args, int *);
  136.   if (gpath != NULL) 
  137.     return (void *)(crayEliminateColor(ListElement(geom, *gpath), gpath + 1));
  138.   LIST_EACH(geom, crayEliminateColor(((List *)geom)->car, NULL));
  139. }
  140.  
  141. void *cray_list_SetColorAll(int sel, Geom *geom, va_list args) {
  142.   List *l = (List *)geom;
  143.   ColorA *c = va_arg(args, ColorA *);
  144.   int *gpath = va_arg(args, int *);
  145.  
  146.   if (gpath != NULL) 
  147.     return (void *)craySetColorAll(ListElement(geom, *gpath), c, gpath + 1);
  148.   LIST_EACH(geom, craySetColorAll(((List *)geom)->car, c, NULL));
  149. }
  150.  
  151. void *cray_list_SetColorAt(int sel, Geom *geom, va_list args) {
  152.   ColorA *c = va_arg(args, ColorA *);
  153.   int vindex = va_arg(args, int), findex = va_arg(args, int),
  154.   *edge = va_arg(args, int *), *gpath = va_arg(args, int *);
  155.   HPoint3 *pt = va_arg(args, HPoint3 *);
  156.   if (gpath != NULL) 
  157.     return (void *)(craySetColorAt(ListElement(geom, *gpath), c, vindex,
  158.                    findex, edge, gpath + 1, pt));
  159.   LIST_EACH(geom, craySetColorAt(((List *)geom)->car, c, vindex, findex,
  160.                  edge, NULL, pt));
  161. }
  162.  
  163. void *cray_list_SetColorAtV(int sel, Geom *geom, va_list args) {
  164.   ColorA *c = va_arg(args, ColorA *);
  165.   int index = va_arg(args, int), *gpath = va_arg(args, int *);
  166.   HPoint3 *pt = va_arg(args, HPoint3 *);
  167.   if (gpath != NULL) 
  168.     return (void *)(craySetColorAtV(ListElement(geom, *gpath), c, index, 
  169.                     gpath + 1, pt));
  170.   LIST_EACH(geom, craySetColorAtV(((List *)geom)->car, c, index, NULL, pt));
  171. }
  172.  
  173. void *cray_list_SetColorAtF(int sel, Geom *geom, va_list args) {
  174.   ColorA *c = va_arg(args, ColorA *);
  175.   int index = va_arg(args, int), *gpath = va_arg(args, int *);
  176.   if (gpath != NULL) 
  177.     return (void *)(craySetColorAtF(ListElement(geom, *gpath), c, index, 
  178.                     gpath + 1));
  179.   LIST_EACH(geom, craySetColorAtF(((List *)geom)->car, c, index, NULL));
  180. }
  181.  
  182. void *cray_list_GetColorAt(int sel, Geom *geom, va_list args) {
  183.   ColorA *c = va_arg(args, ColorA *);
  184.   int vindex = va_arg(args, int), findex = va_arg(args, int),
  185.   *edge = va_arg(args, int *), *gpath = va_arg(args, int *);
  186.   HPoint3 *pt = va_arg(args, HPoint3 *);
  187.   if (gpath != NULL) 
  188.     return (void *)(crayGetColorAt(ListElement(geom, *gpath), c, vindex, 
  189.                    findex, edge, gpath + 1, pt));
  190.   LIST_EACH(geom, crayGetColorAt(((List *)geom)->car, c, vindex, 
  191.                  findex, edge, NULL, pt));
  192. }
  193.  
  194. void *cray_list_GetColorAtV(int sel, Geom *geom, va_list args) {
  195.   ColorA *c = va_arg(args, ColorA *);
  196.   int index = va_arg(args, int), *gpath = va_arg(args, int *);
  197.   HPoint3 *pt = va_arg(args, HPoint3 *);
  198.   if (gpath != NULL)
  199.       return (void *)(crayGetColorAtV(ListElement(geom, *gpath), c, index, 
  200.                       gpath + 1, pt));
  201.   LIST_EACH(geom, crayGetColorAtV(((List *)geom)->car, c, index, NULL, pt));
  202. }
  203.  
  204. void *cray_list_GetColorAtF(int sel, Geom *geom, va_list args) {
  205.   ColorA *c = va_arg(args, ColorA *);
  206.   int index = va_arg(args, int), *gpath = va_arg(args, int *);
  207.   if (gpath != NULL) 
  208.     return (void *)(crayGetColorAtF(ListElement(geom, *gpath), c, index, 
  209.                     gpath + 1));
  210.   LIST_EACH(geom, crayGetColorAtF(((List *)geom)->car, c, index, NULL));
  211. }
  212.